/**
 * cart路由模块
 * routes\carts.js
 */
var express = require('express');
var router = express.Router();
const util = require('../common/util');
const config = require("../common/config");
const cart = require("../controller/cart");
// /* 购物车. */
// router.get('/:user_id', function(req, res, next) {
//   res.send(`<h1>用户${req.params.user_id}购物车</h1>`);
// });

/* 添加商品到购物车. */
/**
 * @swagger
 * /carts/add:
 *   post:
 *     tags:
 *       - cart
 *     summary: 添加购物车
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: string
 *                 example: "20220202222"
 *               product_id:
 *                 type: integer
 *                 example: 1
 *     responses:
 *       201:
 *         description: 购物车添加成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器内部错误
 */
router.post('/add',cart.addcart);

// 购物车商品减1
/**
 @swagger
 * /carts/decrease:
 *   put:
 *     tags:
 *       - cart
 *     summary: 减少购物车
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: string
 *                 example: "20220202222"
 *               product_id:
 *                 type: integer
 *                 example: 1
 *     responses:
 *       201:
 *         description: 购物车减少成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器内部错误
 */
router.put('/decrease',cart.updatecart);

//删除用户购物车中的一条记录
/**
 @swagger
 * /carts/removeOne:
 *   delete:
 *     tags:
 *       - cart
 *     summary: 删除用户购物车中的一条记录
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: string
 *                 example: "20220202222"
 *               product_id:
 *                 type: integer
 *                 example: 1
 *     responses:
 *       201:
 *         description: 购物车删除成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器内部错误
 */
 router.delete('/removeOne',cart.removeOne);

 //删除用户购物车中所有记录
/**
 @swagger
 * /carts/removeall:
 *   delete:
 *     tags:
 *       - cart
 *     summary: 删除用户购物车中所有记录
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               user_id:
 *                 type: string
 *                 example: "20220202222"
 *     responses:
 *       201:
 *         description: 购物车删除成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器内部错误
 */
 router.delete('/removeall',cart.removeall);

 //通过用户Id查询购物车
 /**
  * @swagger
  * /carts/findById/{id}:
  *   get:
  *     tags:
  *       - cart
  *     summary: 通过用户Id查询购物车
  *     parameters:
  *       - in: path
  *         name: id
  *         required: true
  *         schema:
  *           type: string
  *     responses:
  *       200:
  *         description: 成功获取用户信息
  *       404:
  *         description: 用户未找到
  *       500:
  *         description: 服务器内部错误
  */
 router.get('/findById/:id',cart.findById);

module.exports = router;